package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.goods.dto.ExchangeClientDTO;
import com.enation.app.javashop.model.promotion.exchange.dos.ExchangeDO;
import com.enation.app.javashop.model.promotion.tool.dto.PromotionGoodsDTO;
import com.enation.app.javashop.service.promotion.exchange.ExchangeGoodsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author fk
 * @version v2.0
 * @Description: 积分兑换
 * @date 2018/8/21 15:20
 * @since v7.0.0
 */
@RestController
@RequestMapping("/client/exchange")
@ApiIgnore
public class ExchangeGoodsClientController {

    @Autowired
    private ExchangeGoodsManager exchangeGoodsManager;

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    ExchangeDO add(@RequestBody ExchangeClientDTO dto){
        ExchangeDO exchange = dto.getExchangeSetting();
        PromotionGoodsDTO goodsDTO = dto.getGoodsDTO();

        return exchangeGoodsManager.add(exchange, goodsDTO);
    }

    /**
     * 修改积分兑换
     * @param dto 商品DTO
     * @return ExchangeSetting 积分兑换
     */
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    ExchangeDO edit(@RequestBody  ExchangeClientDTO dto){

        ExchangeDO exchange = dto.getExchangeSetting();
        PromotionGoodsDTO goodsDTO = dto.getGoodsDTO();

        return exchangeGoodsManager.edit(exchange, goodsDTO);

    }

    @RequestMapping(value = "/{goods_id}",method = RequestMethod.GET)
    ExchangeDO getModelByGoods(@PathVariable("goods_id")Long goodsId){

        return exchangeGoodsManager.getModelByGoods(goodsId);

    }

    @RequestMapping(value = "/{goods_id}/del",method = RequestMethod.POST)
    public void del(@PathVariable("goods_id")Long goodsId) {

        exchangeGoodsManager.deleteByGoods(goodsId);
    }


}
